﻿using SAIM.Models.BLL;
using SAIM.Models.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace SAIM.Models
{

    public class ImmovablesViewModel
    {
        private List<ImmovablesDAL> _Immovables;

        [Required]
        [Display(Name = "Inmueble")]
        public long Immovable { get; set; }

        public IEnumerable<SelectListItem> Immovables
        {
            get { return new SelectList(_Immovables, "Id", "Name"); }
        }

        [Required]
        [Display(Name = "Día y hora")]
        public DateTime ReservationDate { get; set; }

        [Required]
        [Display(Name = "Observaciones")]
        public String Observations { get; set; }

        public ImmovablesViewModel() 
        {
            using (ImmovablesBLL immovables = new ImmovablesBLL())
            {
                _Immovables = immovables.Value ?? new List<ImmovablesDAL>();
            }
        }
    }
    // [View][Controller]'ViewModel'
    public class IndexApplicationViewModel
    {
        public List<Application> userApplications;

        public IndexApplicationViewModel(List<ApplicationsDAL> applications) 
        {
            userApplications = new List<Application>();
            DateTime actualDate = DateTime.Now;
            foreach (ApplicationsDAL application in applications)
            {
                userApplications.Add(new Application()
                    {
                        expiredClass = application.ReservationDate.CompareTo(actualDate) >= 0 ? string.Empty : "danger",
                        urlFile = "/Applications/File/" + application.Id.ToString(),
                        urlSummary = "/Applications/Summary/" + application.Id.ToString(),
                        immovable = application.Immovables.Name,
                        reservationDate = application.ReservationDate.ToString(),
                        userName = application.AspNetUsers.UserName
                    });
            }
        }
    }
    // [View][Controller]'ViewModel'
    public class ManageApplicationsViewModel
    {
        public List<Application> userApplications;

        public ManageApplicationsViewModel(List<ApplicationsDAL> applications)
        {
            userApplications = new List<Application>();
            DateTime actualDate = DateTime.Now;
            foreach (ApplicationsDAL application in applications)
            {
                userApplications.Add(new Application()
                {
                    expiredClass = application.ReservationDate.CompareTo(actualDate) >= 0 ? string.Empty : "danger",
                    urlFile = "/Applications/File/" + application.Id.ToString(),
                    urlSummary = "/Applications/Summary/" + application.Id.ToString(),
                    immovable = application.Immovables.Name,
                    reservationDate = application.ReservationDate.ToString(),
                    userName = application.AspNetUsers.UserName
                });
            }
        }
    }
    // [View][Controller]'ViewModel'
    public class SummaryApplicationViewModel
    {
        public long Id { get; set; }
        public string userName { get; set; }
        public string immovable { get; set; }
        public DateTime reservationDate { get; set; }
        public string observations { get; set; }
        public bool expired { get; set; }

        public SummaryApplicationViewModel(ApplicationsDAL application)
        {
            Id = application.Id;
            userName = application.AspNetUsers.UserName;
            immovable = application.Immovables.Name;
            reservationDate = application.ReservationDate;
            observations = application.observations;
            expired = application.ReservationDate.CompareTo(DateTime.Now.AddDays(1)) < 0;
        }

        public SummaryApplicationViewModel()
        {
        }
    }

    #region Clases auxiliares
    public class Application
    {
        public string expiredClass { get; set; }
        public string urlFile { get; set; }
        public string urlSummary { get; set; }
        public string immovable { get; set; }
        public string reservationDate { get; set; }
        public string userName { get; set; }
    }
    #endregion
}